package com.dsw.rebbit.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 获取连接的工具类
 */
public class ConnectionUtils {
    /**
     * 获取连接
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //创建工厂
        ConnectionFactory factory=new ConnectionFactory();
        //连接的主机地址
        factory.setHost("127.0.0.1");
        //连接的端口号amqp协议连接
        factory.setPort(5672);
        //连接的具体仓库
        factory.setVirtualHost("/vhost_Dsw");
        //用户名
        factory.setUsername("dsw");
        //密码
        factory.setPassword("123");
        return factory.newConnection();
    }
}
